// App2.js

import React from "react";
import ErrorBoundary from "./ErrorBoundary"

const Profile = ({user}) => <div>name: {user.name}</div>;

class App2 extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            user: { name: 'react' }
        };
    }

    // set the user to null to mock the excetion.
    onClick = () => {
        this.setState({ user: null });
    }

    render() {
        return (
            <div>
                <ErrorBoundary>
                    <Profile user={this.state.user} />
                </ErrorBoundary>
                <button onClick={this.onClick}>update</button>
            </div>
        );
    }
}

export default App2;
